package com.zsc.projectmanagementapi.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
public class ServerResponse {
    private int status;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String token;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    private ServerResponse(int status,String msg){
        this.status = status;
        this.msg = msg;
    }

    private ServerResponse(int status,String msg, Object data){
        this.status = status;
        this.msg = msg;
        this.data = data;
    }
    private ServerResponse(int status,String msg, Object data,String token){
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.token = token;
    }
    //成功操作
    public static ServerResponse createBySuccess(Object data){
        return new ServerResponse(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc(),data);
    }


    /**
     * 操作成功，新加全部自定义
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static ServerResponse createBySuccess(int code, String message,Object data){
        return new ServerResponse(code,message,data);
    }

    public static ServerResponse createBySuccess(Object data,String token){
        return new ServerResponse(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc(),data,token);
    }
    //操作失败
    public static ServerResponse createByError(Object data){
        return new ServerResponse(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc(),data);
    }


    /**
     * 操作失败，新加全部自定义
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static ServerResponse createByError(int code, String message,Object data){
        return new ServerResponse(code,message,data);
    }

    //未都经过登录认证
    public static ServerResponse createUnLoginError(Object data){
        return new ServerResponse(ResponseCode.UNLOGIN.getCode(),ResponseCode.UNLOGIN.getDesc(),data);
    }
    //未经过授权
    public static ServerResponse createUnAuthorizedError(Object data){
        return new ServerResponse(ResponseCode.UNAUTHORIZED.getCode(),ResponseCode.UNAUTHORIZED.getDesc(),data);
    }
    //登录失败
    public static ServerResponse createLoginFail(Object data){
        return new ServerResponse(ResponseCode.LOGIN_FAIL.getCode(),ResponseCode.LOGIN_FAIL.getDesc(),data);
    }
    //自定义异常
    public static ServerResponse createExceptionMessage(int status,String msg){
        return new ServerResponse(status,msg);
    }


//    //用户已存在
//    public static ServerResponse createUserIsExist(){
//        return new ServerResponse(ResponseCode.USERIDISEXIST.getCode(),ResponseCode.USERIDISEXIST.getDesc());
//    }
//    //手机好不存在
//    public static ServerResponse createPhoneIsNotExist(){
//        return new ServerResponse(ResponseCode.PHONEISNOTEXIST.getCode(),ResponseCode.PHONEISNOTEXIST.getDesc());
//    }
//
//    //项目组已存在
//    public static ServerResponse createGroupIsExist(){
//        return new ServerResponse(ResponseCode.GROUPISEXIST.getCode(),ResponseCode.GROUPISEXIST.getDesc());
//    }
//
//    //当前用户已加入该组
//    public static ServerResponse createUserGroupIsExist(){
//        return new ServerResponse(ResponseCode.USERGROUPISEXIST.getCode(),ResponseCode.USERGROUPISEXIST.getDesc());
//    }
//
//    //当前用户不存在该组
//    public static ServerResponse createUserIsNotExistGroup(){
//        return new ServerResponse(ResponseCode.USERISNOTEXISTGROUP.getCode(),ResponseCode.USERISNOTEXISTGROUP.getDesc());
//    }
//
//    //当前计划的负责人不是登录的用户
//    public static ServerResponse createUserIsNotPrincipal(){
//        return new ServerResponse(ResponseCode.USERISNOTPRINCIPAL.getCode(),ResponseCode.USERISNOTPRINCIPAL.getDesc());
//    }
//
//    //该项目组的信息已添加
//    public static ServerResponse createGroupInfoIsExist(){
//        return new ServerResponse(ResponseCode.GROUPINFOISEXIST.getCode(),ResponseCode.GROUPINFOISEXIST.getDesc());
//    }
//
//    //用户名或密码错误
//    public static ServerResponse createPasswordIsError(){
//        return new ServerResponse(ResponseCode.PASSWORDISERROR.getCode(),ResponseCode.PASSWORDISERROR.getDesc());
//    }


}
